<?php
/**
 * Created by PhpStorm.
 * User: Mak
 * Date: 2016/3/12
 * Time: 13:57
 */

namespace Home\Model;
use Think\Model;

class StuInfoModel extends Model{
    protected $tableName = "stuinfo";


    // 得到所有学生表中的记录
    public function getList() {
        $ret = $this->order('username asc')->select();
        return $ret;
    }

    // 根据学号取得学生个人信息
    public function getItem($username){
        $condition['username'] = $username;
        $ret = $this->where($condition)->find();
        return $ret;
    }


    // 验证登陆，返回1-正确；0；密码错； -1：用户名错。
    public function checkUser($username, $password){
        $username      = trim($username);
        $password = trim($password);
        $username = htmlspecialchars($username);
        $password = htmlspecialchars($password);
        $ret = $this->getItem($username);
        if (count($ret)>0) {
            if ($ret['password'] === $password){
                return 1;   // 正确
            }else {
                return 0;  // 密码错误
            }
        }else {
            return -1;  // 账号不存在或错误。
        }
    }
}